//
//  AppController.m
//  KDCalendarControl
//
//  Created by Keith Duncan on 26/06/2007.
//  Copyright 2007 __MyCompanyName__. All rights reserved.
//

#import "AppController.h"

#import "AFCalendarControl.h"
#import "AFWeekControl.h"

@interface AppController ()
@property (readwrite, retain) NSDate *selectedDate;
@end

@implementation AppController

@synthesize selectedDate;

- (id)init {
	[super init];
	
	self.selectedDate = [NSDate date];
	
	enabledDays = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
				   [NSNumber numberWithBool:NO], AFKeyForWeekday(SUNDAY),
				   [NSNumber numberWithBool:YES], AFKeyForWeekday(MONDAY),
				   [NSNumber numberWithBool:YES], AFKeyForWeekday(TUESDAY),
				   [NSNumber numberWithBool:YES], AFKeyForWeekday(WEDNESDAY),
				   [NSNumber numberWithBool:YES], AFKeyForWeekday(THURSDAY),
				   [NSNumber numberWithBool:YES], AFKeyForWeekday(FRIDAY),
				   [NSNumber numberWithBool:NO], AFKeyForWeekday(SATURDAY),
				   nil];
	
	return self;
}

- (void)dealloc {
	[selectedDate release];
	[enabledDays release];
	
	[super dealloc];
}

- (void)_changeSelectedDate:(NSTimer *)timer {
	self.selectedDate = [self.selectedDate dateByAddingDays:1];
}

- (void)awakeFromNib {
	[calendarView bind:@"selectedDate" toObject:self withKeyPath:@"selectedDate" options:nil];
}

@end

@implementation AppController (DataSource)

- (BOOL)weekview:(AFWeekControl *)view isEnabledForDay:(AFWeekday)day {
	return [[enabledDays objectForKey:AFKeyForWeekday(day)] boolValue];
}

- (void)weekview:(AFWeekControl *)view setEnabled:(BOOL)enabled forDay:(AFWeekday)day {
	[enabledDays setValue:[NSNumber numberWithBool:enabled] forKey:AFKeyForWeekday(day)];
}

@end
